Skip to content

fix(host): correct schema name in new data modules, sync init.sql, update tests - #47

Open
TalkingJupiter wants to merge 1 commit into
mainfrom
fix/host-schema-and-tests
Open

fix(host): correct schema name in new data modules, sync init.sql, update tests#47
TalkingJupiter wants to merge 1 commit into
mainfrom
fix/host-schema-and-tests

Conversation

@TalkingJupiter

Copy link
Copy Markdown
Owner

Follow-up to the per-table data module refactor (2208831). Two of the new modules could never have worked, init.sql had drifted from the deployed schema, and the provisioning tests still targeted the pre-refactor API.

Silent failures in the new modules

current_state.get_recent and unknown_devices.record both queried repacss_enviroment (missing the n), which is not a schema under either spelling. Both wrap their SQL in a log-and-continue except, so they failed silently: get_recent always returned {}, and every unknown-device record was dropped with only a printed error. device_registry and ingestion_service spell it correctly, so only the two new modules were affected.

init.sql was the stale side

It still described unknown_devices as (first_seen, last_seen, message_count_24h) while the deployed table and the module use hit_count plus last_payload. Updated init.sql to match the database rather than changing the code.

Also documented in the schema that hit_count is a running total, not a rolling window: nothing trims it, so the "24 h count" the README describes is a query over hit_count and last_seen, not a maintained counter. That distinction was implied by the old column name and is now explicit.

Tests

The refactor removed is_enabled, get_device_state and upsert_device_state from provisioning_service, leaving 13 tests failing against a non-existent API. Rewritten:

  • build_config now takes enabled straight from the registry row (the role filter is gone since device_map.enabled is the truth), plus a case for enabled:false passing through as an applied config.
  • Unknown devices are recorded and deliberately not answered, so the device stays unconfigured and keeps helloing. That behavior is now asserted rather than assumed.
  • Added the MAX_HELLO_BYTES oversized-payload drop.
  • New test_current_state.py and test_unknown_devices.py for the extracted modules.

Two of the new tests are regression guards for exactly what went wrong here: one asserts get_recent names repacss_environment.current_status, so the typo cannot come back silently; one passes a SQL-injection string as the MAC and asserts it stays in the parameters tuple rather than the SQL text.

43 tests pass. No behavior changes beyond the two corrected schema names.

Not addressed

ingestion_service.handle_unknown_device() is still a no-op, so unknown telemetry is dropped silently while provisioning now records unknown hellos. Wiring it to unknown_devices.record needs rate-limiting first, since telemetry arrives every 5 s.

…, update tests

current_state.get_recent and unknown_devices.record both queried
repacss_enviroment, which is not a schema under either spelling. Both wrap
their SQL in a log-and-continue except, so they failed silently: get_recent
always returned {} and every unknown device record was dropped with only a
printed error.

init.sql still described unknown_devices as (first_seen, last_seen,
message_count_24h) while the deployed table and the module use hit_count
plus last_payload. Bring init.sql in line with the database rather than
changing the code, and note that hit_count is a running total: nothing
trims it, so the 24 hour summary in the README is a query over hit_count
and last_seen, not a maintained counter.

Update the provisioning tests for the data-module refactor: is_enabled,
get_device_state and upsert_device_state are gone or moved, build_config
now takes enabled straight from the registry row, and an unknown device is
recorded and deliberately not answered so it keeps helloing. Add tests for
current_state and unknown_devices, including guards for the schema name and
for keeping an untrusted mac in the parameters rather than the SQL text.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant